package com.pengtu.gsj.service.impl.system;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.pengtu.gsj.dao.base.QueryFilter;
import com.pengtu.gsj.dao.base.QueryFilter.MatchType;
import com.pengtu.gsj.dao.system.TrajectoryDao;
import com.pengtu.gsj.entity.app.Trajectory;
import com.pengtu.gsj.service.system.TrajectoryService;
import com.pengtu.gsj.utils.DateUtils;
import com.pengtu.gsj.utils.UserUtils;

@Service
@Transactional
public class TrajectoryServiceImpl implements TrajectoryService {
	
	@Autowired
	private TrajectoryDao trajectoryDao;

	@Override
	public void save(Trajectory trajectory) {
		trajectoryDao.save(trajectory);
	}

	@Override
	public List<Trajectory> getTrajectories() {
		return trajectoryDao.getTrajectories(UserUtils.getUser().getId());
	}

	@Override
	public List<Trajectory> getTrajectoriesByUserId(String menuId, String userId) throws Exception {
		QueryFilter queryFilter = new QueryFilter();
		queryFilter.addFilter("userId", userId, MatchType.EQ);
		queryFilter.addFilter("sysmenuId", menuId, MatchType.EQ);
		//操作记录在同一天
		queryFilter.addFilter("operateTime", DateUtils.getDataStart(), MatchType.GE);
		queryFilter.addFilter("operateTime", DateUtils.getDataEnd(), MatchType.LT);
		return trajectoryDao.find(queryFilter);
	}

}
